package com.yimicloud.common.freemarker;

import com.yimicloud.common.svn.SvnUtil;
import org.tmatesoft.svn.core.SVNCommitInfo;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Justin on 2015/9/7.
 */
public class FreemarkerCode {
    public FreemarkerCode() {
    }

    public static void main(String[] args) throws Exception {
        String appName = "passApplicaition";
        String userName = "wangjingsong";
        String passWord = "wangjingsong";
        (new StringBuilder("svn://10.51.58.128/appCode/")).append(appName).toString();
        String freeMarkerPath = "C:\\Users\\admin\\Desktop\\paas\\paasFreemarker";
        String fileName = "outCode";
        (new StringBuilder("C:\\Users\\admin\\Desktop\\paas\\")).append(fileName).toString();
        HashMap map = new HashMap();
        map.put("mode_name", appName);
        map.put("mode_name_x", appName.toLowerCase());
        map.put("project", ".project");
        map.put("service_url", "${service.url}");
        File file = new File(freeMarkerPath);
        outCode(map, file, fileName);
    }

    public static long improtCode(String userName, String passWord, String appName, String svnUrl, String path) throws SVNException {
        File fileCode = new File(path + "/" + appName);
        SVNURL svnurl2 = SVNURL.parseURIEncoded(svnUrl);
        SVNCommitInfo info = SvnUtil.importDirectory(SvnUtil.authSvn(svnUrl, userName, passWord), fileCode, svnurl2, "初始代码", true);
        long lg = info.getNewRevision();
        System.out.println("============>" + info.getNewRevision());
        return lg;
    }

    public static boolean outCode(Map map, File file, String fileName) throws Exception {
        CodeGenerator codeGenerator = new CodeGenerator(file, map);
        codeGenerator.setApplicationName(fileName);
        return codeGenerator.generateCode();
    }
}
